package com.swsc.solarverse.schedule;

import com.swsc.solarverse.common.util.LocalDateTimeUtils;
import com.swsc.solarverse.service.schedule.ForwardScadaDataTransformSchduleService;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;

/**
 * @Author chencl
 * @Date 2024/6/13 16:22
 * @Version 1.0
 * @Description
 */
@lombok.extern.slf4j.Slf4j
@org.springframework.stereotype.Component
public class ForwardScadaDataTransformSchduleTask {
    private final ForwardScadaDataTransformSchduleService forwardScadaDataTransformSchduleService;

    public ForwardScadaDataTransformSchduleTask(ForwardScadaDataTransformSchduleService forwardScadaDataTransformSchduleService) {
        this.forwardScadaDataTransformSchduleService = forwardScadaDataTransformSchduleService;
    }


    @Scheduled(cron = "0 30 1 * * ?")
    public void createTableMonthSharding() {
        log.info("执行生成表定时任务开始.");
        LocalDateTime now = LocalDateTime.now();
        String currentSuffix = LocalDateTimeUtils.time2Str(now, "yyyyMM");
        forwardScadaDataTransformSchduleService.createTableMonthSharding(currentSuffix);
        String nextSuffix = LocalDateTimeUtils.time2Str(now.plusMonths(1), "yyyyMM");
        forwardScadaDataTransformSchduleService.createTableMonthSharding(nextSuffix);
        log.info("执行生成表定时任务结束: {}, {}.", currentSuffix, nextSuffix);

    }

}
